//
//  RNOneViewController.m
//  MyRnApp
//
//  Created by 朱献国 on 2018/8/7.
//  Copyright © 2018年 Facebook. All rights reserved.
//

#import "RNOneViewController.h"
#import "NativeRedController.h"

#import <React/RCTRootView.h>
#import "MBProgressHUD.h"

@interface RNOneViewController ()

@end

@implementation RNOneViewController

- (void)viewDidLoad {
  [super viewDidLoad];
  
  NSURL *jsCodeLocation;
  
//  jsCodeLocation = [NSURL URLWithString:@"http://192.168.121.40:8081/index.ios.bundle?platform=ios"];
    //发布APP的时候用
    jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"index.ios" withExtension:@"jsbundle"];
  
  RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
                                                      moduleName:@"RNToNativePageDemo"
                                               initialProperties:nil
                                                   launchOptions:nil];
  rootView.backgroundColor = [UIColor whiteColor];
  self.view = rootView;
    
    [self showHud];
  
  [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pushToNext) name:@"test" object:nil];
}

- (void)showHud {
    // 显示 hud
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ // 延时 0.2s
        // 隐藏hud
        [MBProgressHUD hideHUDForView:self.view animated:YES];
    });
}

- (void)pushToNext {
  [self.navigationController pushViewController:[NativeRedController new] animated:YES];
}

- (void)dealloc {
  [[NSNotificationCenter defaultCenter] removeObserver:self];
}

@end
